﻿<UserControl x:Class="BookvarWpf.Controls.ProgressAnimation"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:BookvarWpf.Controls">

  <UserControl.Resources>
    

    <Storyboard x:Key="StartProgressAnimation" RepeatBehavior="Forever">
      <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" RepeatBehavior="Forever" Storyboard.TargetName="progress" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
        <SplineDoubleKeyFrame KeyTime="00:00:03.1000000" Value="720.117"/>
      </DoubleAnimationUsingKeyFrames>
      <PointAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="path"  AutoReverse="True" RepeatBehavior="Forever"  Storyboard.TargetProperty="(Shape.Fill).(RadialGradientBrush.GradientOrigin)">
        <SplinePointKeyFrame KeyTime="00:00:01.3000000" Value="0.855,1.143"/>
      </PointAnimationUsingKeyFrames>
      <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="path1" AutoReverse="True" RepeatBehavior="Forever" Storyboard.TargetProperty="(Shape.Fill).(Brush.RelativeTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1.385"/>
        <SplineDoubleKeyFrame KeyTime="00:00:01.3000000" Value="1.163"/>
      </DoubleAnimationUsingKeyFrames>
      <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="path1" AutoReverse="True" RepeatBehavior="Forever"  Storyboard.TargetProperty="(Shape.Fill).(Brush.RelativeTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1.385"/>
        <SplineDoubleKeyFrame KeyTime="00:00:01.3000000" Value="1.163"/>
      </DoubleAnimationUsingKeyFrames>
      <PointAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="path1" AutoReverse="True" RepeatBehavior="Forever"  Storyboard.TargetProperty="(Shape.Fill).(RadialGradientBrush.GradientOrigin)">
        <SplinePointKeyFrame KeyTime="00:00:01.3000000" Value="0.817,0.963"/>
      </PointAnimationUsingKeyFrames>
      <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="path1" AutoReverse="True" RepeatBehavior="Forever" Storyboard.TargetProperty="(Shape.Fill).(Brush.RelativeTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.006"/>
        <SplineDoubleKeyFrame KeyTime="00:00:01.3000000" Value="0.084"/>
      </DoubleAnimationUsingKeyFrames>
      <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="path1" AutoReverse="True" RepeatBehavior="Forever" Storyboard.TargetProperty="(Shape.Fill).(Brush.RelativeTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.006"/>
        <SplineDoubleKeyFrame KeyTime="00:00:01.3000000" Value="0.149"/>
      </DoubleAnimationUsingKeyFrames>
      <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="path1" AutoReverse="True" RepeatBehavior="Forever" Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)">
        <SplineColorKeyFrame KeyTime="00:00:00" Value="#FFFCFF00"/>
        <SplineColorKeyFrame KeyTime="00:00:01.3000000" Value="#FFFCFF00"/>
      </ColorAnimationUsingKeyFrames>
      <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="path" AutoReverse="True" RepeatBehavior="Forever" Storyboard.TargetProperty="(Shape.Fill).(Brush.RelativeTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1.372"/>
        <SplineDoubleKeyFrame KeyTime="00:00:01.3000000" Value="1"/>
      </DoubleAnimationUsingKeyFrames>
      <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="path" AutoReverse="True" RepeatBehavior="Forever" Storyboard.TargetProperty="(Shape.Fill).(Brush.RelativeTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1.372"/>
        <SplineDoubleKeyFrame KeyTime="00:00:01.3000000" Value="1"/>
      </DoubleAnimationUsingKeyFrames>
      <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="path" AutoReverse="True" RepeatBehavior="Forever" Storyboard.TargetProperty="(Shape.Fill).(Brush.RelativeTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="-0.025"/>
        <SplineDoubleKeyFrame KeyTime="00:00:01.3000000" Value="0"/>
      </DoubleAnimationUsingKeyFrames>
      <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="path" AutoReverse="True" RepeatBehavior="Forever" Storyboard.TargetProperty="(Shape.Fill).(Brush.RelativeTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="-0.006"/>
        <SplineDoubleKeyFrame KeyTime="00:00:01.3000000" Value="0"/>
      </DoubleAnimationUsingKeyFrames>
    </Storyboard>

    <Storyboard x:Key="StopProgressAnimation">
      <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="progress" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0" />
        <SplineDoubleKeyFrame KeyTime="00:00:01" Value="360" />
      </DoubleAnimationUsingKeyFrames>
    </Storyboard>
    <Storyboard x:Key="FadeInProgressAnimation">
      <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="progress" Storyboard.TargetProperty="(UIElement.Opacity)">
        <SplineDoubleKeyFrame KeyTime="00:00:01" Value="1" />
      </DoubleAnimationUsingKeyFrames>
    </Storyboard>
    <Storyboard x:Key="FadeOutProgressAnimation">
      <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="progress" Storyboard.TargetProperty="(UIElement.Opacity)">
        <SplineDoubleKeyFrame KeyTime="00:00:01" Value="0" />
      </DoubleAnimationUsingKeyFrames>
    </Storyboard>

  </UserControl.Resources>

  <UserControl.Triggers>
    <EventTrigger RoutedEvent="local:ProgressAnimation.AnimationStart">
      <BeginStoryboard Storyboard="{StaticResource FadeInProgressAnimation}" />
      <BeginStoryboard Storyboard="{StaticResource StartProgressAnimation}" />
    </EventTrigger>
    <EventTrigger RoutedEvent="local:ProgressAnimation.AnimationStop">
      <BeginStoryboard HandoffBehavior="Compose" Storyboard="{StaticResource StopProgressAnimation}" />
      <BeginStoryboard Storyboard="{StaticResource FadeOutProgressAnimation}" />
    </EventTrigger>

  </UserControl.Triggers>

  <Canvas Width="152.5" Height="105.517" Grid.Row="1" Grid.ColumnSpan="2" x:Name="progress" Opacity="0"
           IsHitTestVisible="false" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5">
    <Canvas.RenderTransform>
      <TransformGroup>
        <ScaleTransform ScaleX="1" ScaleY="1" />
        <SkewTransform AngleX="0" AngleY="0" />
        <RotateTransform Angle="0" />
        <TranslateTransform X="0" Y="0" />
      </TransformGroup>
    </Canvas.RenderTransform>

    <Path Stretch="Fill" Stroke="#FFFFBB00" StrokeThickness="0" Margin="31,0,4,25.891" x:Name="path" Grid.ColumnSpan="2" Data="M472,456 C472,456 488.13494,434.15154 509.00016,442.49805 531.50008,451.49847 530.5,468.49999 530.5,468.49999 L506.49988,471.99926 544.62063,501.23539 576.00044,461.75001 549.25032,465.74896 C549.25032,465.74896 546.7502,437.24768 519.99999,426.24717 484.45454,411.62979 459.49953,445.74787 459.49953,445.74787 z">
      <Path.Fill>
        <RadialGradientBrush>
          <RadialGradientBrush.RelativeTransform>
            <TransformGroup>
              <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="1" ScaleY="1"/>
              <SkewTransform AngleX="0" AngleY="0" CenterX="0.5" CenterY="0.5"/>
              <RotateTransform Angle="0" CenterX="0.5" CenterY="0.5"/>
              <TranslateTransform X="0" Y="0"/>
            </TransformGroup>
          </RadialGradientBrush.RelativeTransform>
          <GradientStop Color="#FF9CCD00" Offset="0.043"/>
          <GradientStop Color="#FFC2FF00" Offset="0.416"/>
          <GradientStop Color="#F9A0CF0B" Offset="0.684"/>
          <GradientStop Color="#00A0CF0B" Offset="1"/>
        </RadialGradientBrush>
      </Path.Fill>
    </Path>
    <Path Stretch="Fill" Stroke="#FFB7F005" Data="M472,456 C472,456 488.13494,434.15154 509.00016,442.49805 531.50008,451.49847 530.5,468.49999 530.5,468.49999 L506.49988,471.99926 544.62063,501.23539 576.00044,461.75001 549.25032,465.74896 C549.25032,465.74896 546.7502,437.24768 519.99999,426.24717 484.45454,411.62979 459.49953,445.74787 459.49953,445.74787 z" RenderTransformOrigin="0.5,0.5" StrokeThickness="0" Margin="-1,23.891,36,2" x:Name="path1" Grid.ColumnSpan="2">
      <Path.Fill>
        <RadialGradientBrush>
          <RadialGradientBrush.RelativeTransform>
            <TransformGroup>
              <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="1" ScaleY="1"/>
              <SkewTransform AngleX="0" AngleY="0" CenterX="0.5" CenterY="0.5"/>
              <RotateTransform Angle="0" CenterX="0.5" CenterY="0.5"/>
              <TranslateTransform X="0" Y="0"/>
            </TransformGroup>
          </RadialGradientBrush.RelativeTransform>
          <GradientStop Color="#FFFFBB00" Offset="0"/>
          <GradientStop Color="#FFFFF7E0" Offset="0.373"/>
          <GradientStop Color="#FFFFBF0F" Offset="0.722"/>
          <GradientStop Color="#00FFBF0F" Offset="1"/>
        </RadialGradientBrush>
      </Path.Fill>
      <Path.RenderTransform>
        <TransformGroup>
          <ScaleTransform ScaleX="-1" ScaleY="-1"/>
          <SkewTransform AngleX="0" AngleY="0"/>
          <RotateTransform Angle="360"/>
          <TranslateTransform X="0" Y="0"/>
        </TransformGroup>
      </Path.RenderTransform>
    </Path>
  </Canvas>
  
</UserControl>
